﻿namespace Liger.Web.UI
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Liger.Web.Common;
    using Liger.Web.Common.Extensions;

    public class FormFieldBuilder : JObjectBuilderBase, IHideObjectMembers
    {
        protected FormField Field
        {
            get
            {
                return base.Obj as FormField;
            }
        }

        public FormFieldBuilder(FormField Field)
            : base(Field)
        { 
        }

        /// <summary>
        /// 绑定列名
        /// </summary>
        public FormFieldBuilder Name(string value)
        {
            this.Field.Name = value;
            return this;
        }

        /// <summary>
        /// 类型
        /// </summary>
        public FormFieldBuilder Type(string value)
        {
            this.Field.Type = value;
            return this;
        }

        /// <summary>
        /// 是否新行
        /// </summary>
        public FormFieldBuilder Newline(bool value)
        {
            this.Field.Newline = value;
            return this;
        }
        /// <summary>
        /// 分组
        /// </summary>
        public FormFieldBuilder Group(bool value)
        {
            this.Field.Group = value;
            return this;
        }
        /// <summary>
        /// 分组
        /// </summary>
        public FormFieldBuilder Groupicon(string value)
        {
            this.Field.Groupicon = value;
            return this;
        }
        /// <summary>
        /// Label
        /// </summary>
        public FormFieldBuilder Label(string value)
        {
            this.Field.Label = value;
            return this;
        }
        /// <summary>
        /// Label宽度
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public FormFieldBuilder LabelWidth(int value)
        {
            this.Field.LabelWidth = value;
            return this;
        }
        /// <summary>
        /// label对齐方式
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public FormFieldBuilder LabelAlign(string value)
        {
            this.Field.LabelAlign = value;
            return this;
        }
        /// <summary>
        /// 对齐
        /// </summary>
        public FormFieldBuilder Align(string value)
        {
            this.Field.Align = value;
            return this;
        } 

        /// <summary>
        /// Space
        /// </summary>
        public FormFieldBuilder Space(int value)
        {
            this.Field.Space = value;
            return this;
        }
        /// <summary>
        /// 下拉框的文本表单名
        /// </summary>
        public FormFieldBuilder ComboboxName(string value)
        {
            this.Field.ComboboxName = value;
            return this;
        }

        /// <summary>
        /// 设置 attr
        /// </summary>
        /// <param name="property"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public JObjectBuilderBase Attr(string property, string value)
        { 
            if (this.Field.Attr == null)
            {
                this.Field.Attr = new Dictionary<string, string>();
            }
            this.Field.Attr.Add(property, value); 
            return this;
        }

        /// <summary>
        /// 设置 验证
        /// </summary>
        /// <param name="Validate"></param>
        /// <returns></returns>
        public JObjectBuilderBase Validate(Dictionary<string, string> Validate)
        {
            this.Field.Validate = Validate;
            return this;
        }
    }
}
